<%@page import="org.apache.jasper.tagplugins.jstl.core.ForEach"%>
<%@page import="kickboxing.model.Newsy"%>
<%@page import="java.util.List"%>
<%@page import="java.util.Iterator"%>
<%@page import="kickboxing.controller.NewsyManager"%>
<%@page import="kickboxing.model.Uzytkownik"%>



<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>


<a href="../adminPanel.jsp">powrot</a><br>

		<% 
	
		
		
		NewsyManager man = new NewsyManager();
		List <Newsy> listaPRO =  man.wysietlWszystkieNewsy();
		
		int perPage = 4;
		int size = listaPRO.size()-1;
		int pages;
		int start=0;
		
		
		
		
	    if( request.getParameter("pages") != null && request.getParameter("pages") != "")
	    {
	    	pages = (Integer.parseInt(request.getParameter("pages")));
	    	start = (pages - 1) * perPage;
	    	
	    	if(pages < 1)  pages = 1; 
	    	
	    }
	    else
	    {
	    	pages=1;
	    }
	    
	    int prev = pages - 1;
		int next = pages + 1;
	    
	    //out.println("pages: "+pages+"<br>start: "+start+"<br>size: "+size);
	    
	    for(int i = start; i<start+perPage; i++){
	    	
	    	
	    	if(i>size) break;
	    	
	    	
	    	else{ 
	    		%>
	    		<div align=left><b> <font face=Verdana size=1 color=#954930>
	    			<%= listaPRO.get(i).getTemat() %>
	    			</font></b>
	    			<% 
	    			
	    			
	    			//edycja
	    			Uzytkownik user = (Uzytkownik)session.getAttribute("user");
		    		if(user != null){

		    			if(user.getPrawa() == 'a')
		    			{	%>
		    			<a href="../../ckeditor/_samples/edytujNewsCKEDITOR.jsp?id=<%= listaPRO.get(i).getId_newsu() %>&pisal=<%= listaPRO.get(i).getTemat() %>">
		    				<font color=red>edytuj</font></a>
		    			<a href="../usunNewsa.jsp?id=<%= listaPRO.get(i).getId_newsu() %>">
		    				<font color=red>usun</font></a>
		    				<%	
		    			}
		    		}
		    		
		    		
		    		
	    			%>
	    		</div><div align=right><font face=Verdana size=1 color=#954930>
	    			<%= listaPRO.get(i).getData() %>	
	    		</font></div>
	    		<div align=justify><font face=Verdana size=1 >
		    	
		    		<%= listaPRO.get(i).getTresc().trim() %>
		    	
	    		</font>
	    		
	    		</div><hr>
				<%}}
	    
	    if(pages > 1){
	    	out.println("<a href=newsesAdmin.jsp?pages="+prev+">poprzednia strona</a>");
	    }
	    if(pages <= (size/perPage)){
	    	out.println("<a href=newsesAdmin.jsp?pages="+next+">nastepna strona</a>");
	    }
		    		%>
			

